package com.neu.controller;

import com.neu.dto.ShopDTO;
import com.neu.service.ShopService;
import com.neu.utils.ResultModel;
import com.neu.vo.ShopVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    ShopService shopService;

    @GetMapping("/login")
    public ResultModel<ShopVO> login(String name, String password){
        ResultModel<ShopVO> resultModel = new ResultModel<>();
        ShopVO ShopVO = shopService.login(name, password);

        if(ShopVO == null){
            resultModel.setCode(500);
            resultModel.setMsg("登录失败！");
        }else{
            resultModel.setData(ShopVO);
            resultModel.setMsg("登录成功！");
        }
        return resultModel;
    }


    @GetMapping
    public ResultModel<List<ShopVO>> find(ShopDTO shopDTO){
        ResultModel<List<ShopVO>> resultModel = new ResultModel<>();
        List<ShopVO> shopVOList = shopService.find(shopDTO);

        resultModel.setData(shopVOList);
        resultModel.setMsg("获取商家信息成功！");
        return resultModel;
    }

    @GetMapping("/getAllShopInfo")
    public ResultModel<List<ShopVO>> getAllShopInfo(){
        ResultModel<List<ShopVO>> resultModel = new ResultModel<>();
        List<ShopVO> shopVOList = shopService.selectAll();
        resultModel.setCode(200);
        resultModel.setData(shopVOList);
        resultModel.setMsg("获取商家信息成功！");
        return resultModel;
    }

    @GetMapping("/getShopInfo/{bannerId}")
    public ResultModel<List<ShopVO>> getAllShopInfo(@PathVariable("bannerId") Integer bannerId){
        ResultModel<List<ShopVO>> resultModel = new ResultModel<>();
        List<ShopVO> shopVOList = shopService.selectByBannerId(bannerId);
        resultModel.setCode(200);
        resultModel.setData(shopVOList);
        resultModel.setMsg("获取商家信息成功！");
        return resultModel;
    }

}
